import { getUserInfoApi } from "@/request/api"
export default {
    namespaced: true,
    state: {
        userInfo: {
            headImg: require("../../assets/img/849b211b6341ce17468a1a3299c7fef8.png"),
            nickName: "雷电将军",
            coin: 0,
        },
        cartTotal: 6,
    },
    mutations: {
        changeUserInfo(state, payload) {
            state.userInfo = payload.userInfo
            state.cartTotal = payload.cartTotal
        },
        initUserInfo(state) {
            state.userInfo = {
                headImg: require('../../assets/img/userImg.f8bbec5e.png'),
                nickName: "--",
                coin: "--"
            }
            state.cartTotal = 0
        }
    },
    actions: {
        async asyncUpdateUserInfo(context) {
            const getUserInfoRes = await getUserInfoApi();
            // console.log({ getUserInfoRes });
            context.commit("changeUserInfo", getUserInfoRes.data)
        }
    }
}